<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    async function fn() {
      return 1
    }
    console.log(fn());  //打印的promise对象
    fn().then(res => console.log(res)) //打印的是1


    async function fn() {
      throw new Error('我是错误i的')
      return 1
    }
    console.log(fn());  //打印的promise对象
    fn()
      .then(res => console.log(res)) //打印的是1
      .catch(res => console.log(res)) //报错

    async function fn() {
      return 1
    }
    async function fn1() {
      try {
        const res = await fn()  //fn()是立即执行
        const res1 = await Promise.resolve(2) //在执行完res赋值后立即执行
        console.log(res);  // 打印的是1
        console.log(res1)  //打印的是2
      } catch (error) {
        console.log(error)
      } finally {
        console.log('finally')
      }
    }
    fn1()
  </script>
</body>

</html>